import { Component, OnInit, ViewChild } from '@angular/core';
import { Slides, NavParams } from 'ionic-angular';
import { DmTabs } from '../../../lib/dm-ui/dm-tool-tabs/tabs';
import { NavController } from 'ionic-angular';
import { DetailService } from './detail.service';
import { TaskConfig, TaskDetailResponse } from '../../../app/app.service';

import { ApprovePage } from './approve/approve';

@Component({
    selector: 'detail-page',
    templateUrl: 'detail.html'
})
export class DetailPage implements OnInit {

    @ViewChild(Slides) slides: Slides;
    @ViewChild(DmTabs) tabs: DmTabs;

    tabsData: Array<string> = ['基本信息', '报销详情'];
    params: any;
    taskData: any = {};
    page1Data: any = {};
    page2Data: any = {};
    taskConfig: any = {};
    docNum: string = '';

    constructor(public navCtrl: NavController, private detailService: DetailService, private navParams: NavParams) {
        this.taskConfig = TaskConfig;
    }

    ngOnInit() {
        this.docNum = this.navParams.data.doc_num;
        this.params = {
            "page": "1",
            "size": "20",
            "fields": [
                {
                    "field": "task_id",
                    "value": `${this.navParams.data.task_id}`
                }
            ]
        }
        this.detailService.getTaskDetail(this.params).then((res: TaskDetailResponse) => {
            console.log(res);
            if (res.code === 'SUCCESS') {
                this.taskData = res.data;
            }
        });

    }

    goApprove() {
        this.navCtrl.push(ApprovePage, { taskId: this.navParams.data.task_id });
    }

    tabsActived(index: number) {
        this.slides.slideTo(index, 400);
    }

    ionSlideDidChange(slides: Slides) {
        this.tabs.activeItem(slides.getActiveIndex());
    }

}
